import server from '../util/request.js'

export function findAll() {
    return server({ url: '/rm', method: 'GET' })
}
export function findOne() {
    return server({ url: '/rm/a', method: 'GET' })
}
export function findTwo() {
    return server({ url: '/rm/b', method: 'GET' })
}
export function add(data) {
    return server({ url: '/rm', method: 'POST', data })
}
export function update(data) {
    return server({ url: '/rm', method: 'PUT', data })
}
export function update1(data) {
    return server({ url: '/rm/c', method: 'PUT', data })
}
export function deleteById(id) {
    return server({ url: `/rm/${id}`, method: 'DELETE' })
}

// 新增：采购计划多条件查询
export function findPlanByCondition(params) {
    return server({ url: '/procurePlan/condition', method: 'GET', params })
}

// 条件查询
export const findByCondition = (params) => {
    return server({
        url: '/rm/condition',
        method: 'get',
        params
    });
};
export const findByCondition1 = (params) => {
    return server({
        url: '/rm/condition1',
        method: 'get',
        params
    });
};

export const findByCondition2 = (params) => {
    return server({
        url: '/rm/condition2',
        method: 'get',
        params
    });
};
// /* 下拉数据模拟（后续可换真实） */
// export function getUnitOpts() {
//     return Promise.resolve([
//         { label: '千克', value: 1 },
//         { label: '吨', value: 2 },
//         { label: '升', value: 3 }
//     ])
// }
// export function getEmpOpts() {
//     return Promise.resolve(
//         [1, 2, 3].map(v => ({ label: `员工-${v}`, value: v }))
//     )
// }
// export function getWarehouseOpts() {
//     return Promise.resolve(
//         [10, 11].map(v => ({ label: `仓库-${v}`, value: v }))
//     )
// }
// export function getSupplierOpts() {
//     return Promise.resolve(
//         [20, 21].map(v => ({ label: `供应商-${v}`, value: v }))
//     )
// }


/* ===============  真实接口替换  =============== */

/* 1 计量单位 */
export function getUnitOpts() {
    return server({ url: '/unit/findAll', method: 'GET' })
        .then(res => (res?.data?.data || []).map(item => ({ label: item.unitName, value: item.unitId })))
}

/* 2 员工 */
export function getEmpOpts() {
    return server({ url: '/Employee/search', method: 'GET' })
        .then(res => (res?.data?.data || []).map(item => ({ label: item.name, value: item.employeeId })))
}

/* 3 仓库 */
export function getWarehouseOpts() {
    return server({ url: '/warehouse/getAll', method: 'GET' })
        .then(res => (res?.data?.data || []).map(item => ({
            label: item.name, value: item.warehouseId ,address: item.address  })))
}

export function getProOpts() {
    return server({ url: '/product/findAll', method: 'GET' })
        .then(res => (res?.data?.data || []).map(item => ({
            label: item.name, value: item.productId  })))
}

/* 4 供应商 */
export function getSupplierOpts() {
    return server({ url: '/api/suppliers/findAll', method: 'GET' })
        .then(res => (res?.data?.data || []).map(item => ({ label: item.name, value: item.supplierId ,address: item.address })))
}

/* 采购计划简易下拉（带联动字段） */
export function getProcureMini() {
    return server({ url: '/procurePlan/stu', method: 'GET' })
        .then(res => res?.data?.data || [])
}
/* 原材料下拉（带单位/仓库/数量） */
export function getMaterialMini() {
    return server({ url: '/rm/stu', method: 'GET' })
        .then(res => res?.data?.data || [])
}

/* 使用后端 RequisitionVo 下拉（带商品名称） */
export function getRequisitionVo() {
    return server({ url: '/mr/voList', method: 'GET' })
        .then(res => res?.data?.data || [])
}

// 在wms.js中添加
// 在 wms.js 中添加商品发货条件查询接口
export function findShipmentByCondition(params) {
    return server({
        url: '/ps/condition',
        method: 'GET',
        params
    });
}


// 扫码入库
export const scanStockIn = (data) => {
    return server({
        url: '/productInput/scan',  // 对应后端新增的接口地址
        method: 'post',
        data
    })
}
// wms.js 中新增/补充
export function findByInputId(inputId) {
    return server({
        url: `/productInput/${inputId}`,
        method: 'GET'
    })
}
// orderApi.js
// 获取已付款且未发货的订单（用于下拉）
export function getPaidUnshippedOrders() {
    return server({
        url: "/order/paidUnshipped",
        method: "GET"
    });
}
/* --- 原材料领料 --- */
export function findAllRequisition() {
    return server({ url: '/mr', method: 'GET' })
}
export function addRequisition(data) {
    return server({ url: '/mr', method: 'POST', data })
}
export function updateRequisition(data) {
    return server({ url: '/mr', method: 'PUT', data })
}
export function deleteRequisition(id) {
    return server({ url: `/mr/${id}`, method: 'DELETE' })
}


/* --- 成品入库 --- */
export function findAllInput() {
    return server({ url: '/productInput', method: 'GET' })
}
export function addInput(data) {
    return server({ url: '/productInput', method: 'POST', data })
}
export function updateInput(data) {
    return server({ url: '/productInput', method: 'PUT', data })
}
export function deleteInput(id) {
    return server({ url: `/productInput/${id}`, method: 'DELETE' })
}



/* --- 商品发货 --- */
export function findAllShipment() {
    return server({ url: '/ps', method: 'GET' })
}
export function addShipment(data) {
    return server({ url: '/ps', method: 'POST', data })
}
export function updateShipment(data) {
    return server({ url: '/ps', method: 'PUT', data })
}
export function deleteShipment(id) {
    return server({ url: `/ps/${id}`, method: 'DELETE' })
}



/* --- 采购计划 --- */
export function findAllPlan() {
    return server({ url: '/procurePlan', method: 'GET' })
}
export function addPlan(data) {
    return server({ url: '/procurePlan', method: 'POST', data })
}
export function updatePlan(data) {
    return server({ url: '/procurePlan', method: 'PUT', data })
}
export function deletePlan(id) {
    return server({ url: `/procurePlan/${id}`, method: 'DELETE' })
}